/**
 * https://leetcode.cn/problems/find-the-town-judge/submissions/566888990/?envType=daily-question&envId=2024-09-22
 */

class Solution {
public:
    bool visit[1001];
    int findJudge(int n, vector<vector<int>>& trust) {
        int believe[1001]={0};
        int maxt=0;
        int d=1;
        for(int i=0;i<trust.size();++i){
            visit[trust[i][0]]=true;
            if(++believe[trust[i][1]]>maxt){
                maxt=believe[trust[i][1]];
                d=trust[i][1];
            }
        }
        if(maxt<n-1||visit[d])
        return -1;
        return d;
    }
};